# https://www.bilibili.com/video/BV1W7411G7wP/?p=6&spm_id_from=pageDriver&vd_source=8bd7b24b38e3e12c558d839b352b32f4
# 读取Books2.xlsx
import pandas as pd
import copy

books2 = pd.read_excel('../resources/input/Books2.xlsx', index_col='ID')
booksCopy = copy.copy(books2)
booksCopy2 = copy.copy(books2)
booksCopy3 = copy.copy(books2)
booksCopy4 = copy.copy(books2)

# Python风格的函数填充
books2['Price'] = books2['ListPrice'] * books2['Discount']
print(books2)

# 迭代。模拟Excel的填充手柄
print('============================')
print(booksCopy)
for i in booksCopy.index:
    booksCopy['Price'].at[i] = booksCopy['ListPrice'].at[i] * booksCopy['Discount'].at[i]
print(booksCopy)

# 每本书涨价2元
print('============================')
print(booksCopy2)
booksCopy2['ListPrice'] = booksCopy2['ListPrice'] * 2
print(booksCopy2)

# Series的apply方法
print('============================')
def add_2(x):
    return x + 2
print(booksCopy3)
booksCopy3['ListPrice'] = booksCopy3['ListPrice'].apply(add_2)
print(booksCopy3)

# Series的apply方法 - 兰姆达表达式
print('============================')
print(booksCopy4)
booksCopy4['ListPrice'] = booksCopy4['ListPrice'].apply(lambda x: x + 2)
print(booksCopy4)